//
//  main.cpp
//  137.只出现一次的数字II
//
//  Created by Yan Zihao on 2024/10/6.
//

class Solution
{
public:
    int singleNumber(vector<int>& nums)
    {
        int ans = 0;
        for (int i = 0; i < 32; ++i)
        {
            int total = 0;
            for (int num: nums)
            {
                total += ((num >> i) & 1);
            }
            if (total % 3)
            {
                ans |= (1 << i);
            }
        }
        return ans;
    }
};
